Skip to content

docs(start): createIsomorphicFn and envOnly #4806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hokkyss
Copy link

@hokkyss hokkyss commented Jul 28, 2025

Add docs for createIsomorphicFn, serverOnly, and clientOnly.

I am not quite sure whether "environment functions" is a good name though

Summary by CodeRabbit

  • Documentation
    • Added new “Environment Functions” docs for React Start, covering createIsomorphicFn, serverOnly, clientOnly, examples, and tree-shaking behavior.
    • Added Solid Start counterpart via mirrored content aligned with React doc.
    • Updated docs navigation to include “Environment Functions” under React and Solid.
    • Clarified React Server Functions documentation by removing outdated API Route warning and call-source bullets.

@github-actions github-actions bot added the documentation Everything documentation related label Jul 28, 2025
@hokkyss hokkyss changed the title docs(start): environment functions docs docs(start): createIsomorphicFn and envOnly Jul 28, 2025
@hokkyss hokkyss force-pushed the main branch 3 times, most recently from a675dae to 9cab129 Compare July 29, 2025 01:52
### Complete Implementation

```tsx
const getEnv = createIsomorphicFn()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make those snippets complete by adding the import from '@tanstack/solid-start'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applies to all examples

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -0,0 +1,3 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once we have settled on the text for react, please duplicate and change the imports to point to solid

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hokkyss see the docs in docs/router/framework/solid/devtools.md which have a syntax for performing text replacements on the ref doc. So you shouldn't need to duplicate the entire document.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. Updated guys. Thank you

@@ -98,7 +98,7 @@ response?: 'data' | 'full' | 'raw'
- From other server functions

> [!WARNING]
> Server functions cannot be called from API Routes. If you need to share business logic between server functions and API Routes, extract the shared logic into utility functions that can be imported by both.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can now call server functions from API routes. please check and and if true, this text can be removed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schiller-manuel is right. API routes as a whole became the new "Server Routes" which support calling Server Function.

This warning can be removed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, this is deleted

@schiller-manuel
Copy link
Contributor

we also got those docs recently: b402bbc

maybe just improve those where needed?

@@ -98,7 +98,7 @@ response?: 'data' | 'full' | 'raw'
- From other server functions

> [!WARNING]
> Server functions cannot be called from API Routes. If you need to share business logic between server functions and API Routes, extract the shared logic into utility functions that can be imported by both.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schiller-manuel is right. API routes as a whole became the new "Server Routes" which support calling Server Function.

This warning can be removed.

@@ -0,0 +1,3 @@
---
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hokkyss see the docs in docs/router/framework/solid/devtools.md which have a syntax for performing text replacements on the ref doc. So you shouldn't need to duplicate the entire document.

Use `createIsomorphicFn()` to define functions that behave differently depending on whether they are called on the client or the server. This is useful for safely sharing logic across environments while delegating environment-specific behavior to appropriate handlers.

> [!WARNING]
> Unimplemented function results in a no-op function.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of a warning, this could be a small heading like "What is a no-op?", that'd show the user the type of a no-op.

Perhaps something like this:

type NoOpFunction = () => undefined // add a comment here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!
I have added an explanation at the end of createIsomorphicFn as h4

@@ -122,6 +126,10 @@
"label": "Static Server Functions",
"to": "framework/solid/static-server-functions"
},
{
"label": "Environment Functions",
"to": "framework/react/environment-functions"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"to": "framework/react/environment-functions"
"to": "framework/solid/environment-functions"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Updated.

Copy link

coderabbitai bot commented Aug 16, 2025

Walkthrough

Adds “Environment Functions” docs for React and Solid, updates navigation to include them, and removes a warning plus two bullets from the React server functions doc. Solid’s page references the React doc via front matter replace rules.

Changes

Cohort / File(s) Summary of Changes
Docs navigation
docs/start/config.json
Added two nav entries: React and Solid “Environment Functions” links.
React docs
docs/start/framework/react/environment-functions.md, docs/start/framework/react/server-functions.md
Added new doc detailing environment-aware utilities (createIsomorphicFn, serverOnly, clientOnly). Edited server-functions doc to remove API Route warning and two call-source bullets.
Solid docs
docs/start/framework/solid/environment-functions.md
Added YAML front matter referencing React doc with replace mapping from “react” to “solid”.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A bunny hops through docs so bright,
New paths for envs in day and night.
React and Solid, side by side,
Server, client—cleanly tied.
With nibbled notes and tidy links,
The warren’s lore now smoothly syncs. 🥕✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (11)
docs/start/config.json (1)

44-47: Optional: Consider renaming “Environment Functions” to “Isomorphic Utilities”

Since the PR description questions the naming, “Isomorphic Utilities” (or “Environment-aware Utilities”) may better convey the intent without implying only functions. If you prefer this, we should update both the page titles and these nav labels together.

Also applies to: 129-132

docs/start/framework/react/environment-functions.md (9)

10-15: Grammar: “Start provides”

Subject-verb agreement and light copy tweaks.

-Start provide three core environment functions:
+Start provides three core environment functions:

45-48: Grammar: “a no-op” and punctuation

Clarify the client behavior phrasing.

-// ℹ️ On the **client**, it is no-op (returns `undefined`)
+// ℹ️ On the **client**, it is a no-op (returns `undefined`).

59-62: Grammar: “a no-op” and punctuation

Same tweak for the server-side note.

-// ℹ️ On the **server**, it is no-op (returns `undefined`)
+// ℹ️ On the **server**, it is a no-op (returns `undefined`).

73-75: Grammar: “a no-op” and punctuation

Apply the same phrasing/punctuation for consistency.

-// ℹ️ On both **client** and **server**, it is no-op (returns `undefined`)
+// ℹ️ On both **client** and **server**, it is a no-op (returns `undefined`).

88-91: Fix heading: backticks and casing

Current “## envOnly Functions” renders oddly. Prefer plain language.

-## `env`Only Functions
+## Environment-only Functions

117-123: Tree-shaking section: wording and clarity

Minor grammar improvements and clearer phrasing.

-Environment functions are tree-shaken based on the environment for each bundle produced.
+Environment functions are tree-shaken per environment for each produced bundle.

-Functions created using `createIsomorphicFn()` are tree-shaken. All codes inside `.client()` are not included in server bundle, and vice-versa.
+Functions created using `createIsomorphicFn()` are tree-shaken. All code inside `.client()` is excluded from the server bundle, and vice versa.

-On the server, implementation of `clientOnly` functions are replaced with a function that throws an `Error`. The reverse is true for `serverOnly` functions on the client.
+In the server bundle, `clientOnly` implementations are replaced with a function that throws an `Error`. The reverse is true for `serverOnly` functions in the client bundle.

79-85: TS typing for no-op example

If we want to be explicit for TypeScript users, “void” is the idiomatic return type for a no-op (you can still note that it evaluates to undefined at runtime).

-// basic no-op implementation
-function noop() {}
+// basic no-op implementation (TypeScript)
+const noop: () => void = () => {}

99-112: Avoid locking docs to exact error message strings

The quoted error texts might diverge from implementation over time. Suggest describing the behavior generically or quoting less rigidly (e.g., “throws an error on the client/server”).

Would you like me to replace the exact strings with a generic description, or verify the current runtime messages in the codebase to keep them accurate?


1-4: Optional: Page title naming

If you decide to rename the nav label (e.g., to “Isomorphic Utilities”), mirror it here for consistency.

-title: Environment Functions
+title: Isomorphic Utilities
docs/start/framework/solid/environment-functions.md (1)

1-4: Consider adding a capitalized replacement and validate scope

If the source doc contains “React” (capitalized) or other proper nouns, also add a case-sensitive replacement to ensure titles and prose read naturally for Solid. Example:

 ---
 ref: docs/start/framework/react/environment-functions.md
-replace: { 'react': 'solid' }
+replace:
+  {
+    'react': 'solid',
+    'React': 'Solid'
+  }
 ---

Also, confirm the replacement mechanism applies to code blocks as intended (e.g., it should convert @tanstack/react-start to @tanstack/solid-start without affecting unrelated identifiers).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 1ccf7c8 and f464374.

📒 Files selected for processing (4)
  • docs/start/config.json (2 hunks)
  • docs/start/framework/react/environment-functions.md (1 hunks)
  • docs/start/framework/react/server-functions.md (0 hunks)
  • docs/start/framework/solid/environment-functions.md (1 hunks)
💤 Files with no reviewable changes (1)
  • docs/start/framework/react/server-functions.md
🧰 Additional context used
🪛 LanguageTool
docs/start/framework/solid/environment-functions.md

[grammar] ~1-~1: Hier könnte ein Fehler sein.
Context: --- ref: docs/start/framework/react/environment-functions.md replace: { 'react': 'solid' } ---

(QB_NEW_DE)

docs/start/framework/react/environment-functions.md

[grammar] ~12-~12: There might be a mistake here.
Context: ... to both client and server environments. - serverOnly: Ensures a function can only run on the...

(QB_NEW_EN)


[grammar] ~114-~114: There might be a mistake here.
Context: ...be called on the client!" ``` > [!NOTE] > These functions are useful for API acc...

(QB_NEW_EN)


[grammar] ~121-~121: There might be a mistake here.
Context: ...des inside .client() are not included in server bundle, and vice-versa. On the ...

(QB_NEW_EN)

🔇 Additional comments (3)
docs/start/config.json (2)

44-47: Nav entry for React looks good

The route slug matches the new doc file and placement (after Static Server Functions) is consistent.


129-132: Nav entry for Solid looks good

Slug matches the Solid doc and mirrors the React placement.

docs/start/framework/solid/environment-functions.md (1)

1-4: Front matter approach looks good

Using ref + replace keeps the content DRY across frameworks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Everything documentation related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants